<template>
	<!-- ant-card-bordered-->
	<view class="test-panel-controller">

		<view v-if="showImg" class="img-preview">
			<view class="img-preview-content">
				<image style="width: 80%!important;height:80%!important" mode="aspectFit" :src="`${$cdn}${cur_qs.img}`">
				</image>
			</view>
			<view style="width: 100%;display: flex;justify-content: center;">
				<button style="width: 20%;" @click="showImg=false">关闭</button>
			</view>
		</view>

		<!-- 	<span class="fab-title-info">
			模拟考试
		</span> -->
		<view class="quesction-show-info ant-card-bordered">
			<view class="info-content">
				<!-- 	<view class="maxwidth">
				<a-typography-text type="secondary" :style="getColor">
						{{cur_qs.infoname}}--{{cur_qs.s_id}}
					</a-typography-text> 
				 <a-button v-show="controllerStatus.SOUND_QS" @click="openSoundQs">语音读题</a-button>
				
				</view> -->
				<!-- 			<view class="maxwidth" :style="[needResvoeFlex]">
					<a-typography-text style="text-align: left;line-height: 66rpx;font-size:24px!important"
						:style="[getColor,needResvoe]" class="SimFont">
						{{cur_index+1}}. {{cur_qs.q_desc}}
					</a-typography-text>
				</view>
				<view style="margin-top:12px;">

				</view> -->

				<view class="maxwidth" style="display: flex;" :style="[needResvoeFlex]">
					<block v-if="cur_qs.lang_txt=='WY' || cur_qs.lang_txt=='HY'">
						<p lang="ug" style="text-align: left;line-height: 66rpx;margin: 0px;font-size:24px!important"
							class="akf" :style="[getColor,needResvoe]">
							{{cur_qs.q_desc}}
						</p>
						<p lang="zh" style="text-align: left;line-height: 66rpx;margin: 0px;font-size:24px!important"
							class="SimFont" :style="[getColor]">.{{cur_index+1}}</p>
					</block>
					<block v-else>
						<p style="text-align: left;line-height: 66rpx;margin:0px;font-size:24px!important;font-weight: bold;font-family: Microsoft YaHei;"
							:style="[getColor]">
							{{cur_index+1}}.{{cur_qs.q_desc}}
						</p>
					</block>
					<a-button @click="openSoundQs">语音读题</a-button>
				</view>

				<view style="width: 100%;height: 32rpx;">
				</view>
				<checkbox-group @change="onCheckChange">
					<!-- 			<view class="maxwidth" v-for="(item,index) in cur_qs.q_struct" :style="[getColor]">
						<view :style="[needResvoe]">
							<checkbox v-if="cur_qs.q_type == '1'" :checked="cur_qs.check[index]" :value="index+''"
								:disabled="cur_qs.isright!=undefined">
							</checkbox>
							<a-typography-text :style="[getColor,needResvoe]" style="font-size:20px;"
								v-if="cur_qs.q_type!='2'">
								{{label[index]}}. {{item.value}}
							</a-typography-text>
						</view>
					</view> -->

					<view style="display: flex;" class="maxwidth" v-for="(item,index) in cur_qs.q_struct"
						:style="[getColor,needResvoeFlex]">
						<block v-if="cur_qs.lang_txt=='WY' || cur_qs.lang_txt=='HY'">
							<block v-if="cur_qs.q_type!='2'">
								<p style="margin: 0px;font-size:20px;" lang="ug" :style="[getColor,needResvoe]"
									class="akf" v-if="cur_qs.q_type!='2'">
									{{item.value}}
								</p>
								<p lang="zh" style="text-align: left;line-height: 66rpx;margin:0px;font-size:20px;"
									:style="[getColor]">.{{label[index]}}</p>

								<checkbox v-if="cur_qs.q_type == '1'" :checked="cur_qs.check[index]" :value="index+''"
									:disabled="cur_qs.isright!=undefined">
								</checkbox>
							</block>
						</block>
						<block v-else>
							<checkbox v-if="cur_qs.q_type == '1'" :checked="cur_qs.check[index]" :value="index+''"
								:disabled="cur_qs.isright!=undefined">
							</checkbox>
							<p v-if="cur_qs.q_type!='2'" lang="zh"
								style="text-align: left;line-height: 66rpx;margin: 0px;font-size:20px;font-weight: bold;font-family: Microsoft YaHei;"
								:style="[getColor]">
								{{label[index]}}. {{item.value}}
							</p>
						</block>
					</view>
				</checkbox-group>

				<!-- 	<view class="maxwidth" v-for="(item,index) in cur_qs.q_struct" :style="getColor">
					<view>
						<a-checkbox v-if="cur_qs.q_type == '1'" v-model:checked="cur_qs.check[index]" :value="index" class="SimFont"
							@change="onCheckChange">
						</a-checkbox>
						<a-typography-text :style="getColor" style="line-height: 66rpx;" class="SimFont">
							{{label[index]}}. {{item.value}}
						</a-typography-text>
					</view>
				</view> -->
			</view>

		</view>
		<view class="quesction-ans-info ant-card-bordered" v-show="controllerStatus.SHOW_EXPLAN">
			<a-typography-paragraph>
				{{cur_qs.q_analyse}}
			</a-typography-paragraph>>
		</view>
		<view class="quesction-controller-box ant-card-bordered">
			<view class="maxwidth ans">
				<a-row class="maxwidth" type="flex" v-if="cur_qs!=null" align="middle">
					<a-col flex="6">
						<a-row>

							<a-col :span="24">
								<a-typography-text style="color: red;font-size: 36rpx;" class="SimFont">
									{{textInfo[cur_qs.q_type]['tips']}}
								</a-typography-text>
							</a-col>

						</a-row>
						<a-row>

							<a-col :span="24">
								<a-typography-text style="font-size: 16px;">
									请在备选答案中选择你认为正确的答案!
								</a-typography-text>
							</a-col>

						</a-row>
					</a-col>
					<a-col flex="6">
						<a-row justify="start">
							<a-col style="margin-left:32px">
								<a-button @click="last()">上一题</a-button>
							</a-col>
							<a-col style="margin-left:32px">
								<a-button @click="next()">下一题</a-button>
							</a-col>
							<a-col style="margin-left:32px">
								<a-button @click="setLastInfo">交卷</a-button>
							</a-col>
						</a-row>
					</a-col>
				</a-row>
			</view>
		</view>
		<view class="ant-card-bordered quesction-change-box">
			<a-skeleton active :loading="cur_qs==null">
			</a-skeleton>


			<a-row type="flex" style="align-items: center;width: 100%;">
				<a-col :flex="2" style="align-self: center;">
					<a-typography-text style="color: blue;font-size: 36rpx" class="SimFont">
						你选择的答案:
					</a-typography-text>

					<template v-if="cur_qs.showAns===true">
						<a-tag style="font-size: 24px;padding:12px" v-for="(item,index) in getChangeAns">
							{{item}}
						</a-tag>
					</template>
					<uni-icons style="margin-top:12rpx" :type="cur_qs.isright?'checkmarkempty':'closeempty'"
						:color="cur_qs.isright?'#36e206':'#ff1010'" size="32"
						v-if="controllerStatus.SHOW_RIGHT_OR_ERR && cur_qs.isright!=undefined">
					</uni-icons>
				</a-col>
				<!-- 	<a-col :flex="2" v-show="controllerStatus.SHOW_ANS && cur_qs.isright == false ">
					<a-typography-text>
						正确答案:
					</a-typography-text>
					<a-tag style="font-size: 24px;padding:12px"
						v-for="(item,index) in textInfo[cur_qs.q_type].getAns(cur_qs)">
						{{item}}
					</a-tag>
				</a-col> -->
				<a-col :flex="3" v-if="cur_qs.isright!=true && cur_qs.isright !== false"
					style="display: flex;justify-content: right;">
					<!-- <a-typography-text>
						选择:
					</a-typography-text> -->
					<a-tag style="font-size:24px;padding:12px" v-for="(item,index) in cur_qs.q_struct" :closable="false"
						:class="{'onchangeSpan':cur_qs.check[index],'ondefaultSpan':cur_qs.check[index]==false}"
						@click="tiggerItem(item.index,index)">
						{{textInfo[cur_qs.q_type]['label'][index]}}
					</a-tag>


					<a-button v-if="cur_qs.q_type=='1' && !cur_qs.showAns" @click="showAns(2)">确定</a-button>
				</a-col>
				<!-- 	<a-col style="display: flex;justify-content: center;">
					<a-button v-if="hasLast" @click="lastSubmit">确定</a-button>
				</a-col> -->
			</a-row>



		</view>
		<view class="quesction-img-box" v-if="imgUrl">
			<view class="imageshow-box">
				<!-- <a-image class="imageshow" :src="`${$cdn}${cur_qs.img}`" height="250" :preview="true" /> -->
				<!-- 	<image @click="isShowImg"  :src="`${$cdn}${cur_qs.img}`"
				 
				 style="height:150px;width:300px;" mode="aspectFit" /> -->


				<img @click="isShowImg" :src="imgUrl" style="max-height:170px;max-width:800px;object-fit:scale-down;" />
			</view>
		</view>
	</view>
</template>

<script>
	import {
		toRaw
	} from "vue"
	let db = uniCloud.database()
	let dbCmd = db.command
	export default {
		name: "test-mockreal-controller",
		props: {
			getTestTime: null,
			needCache: {
				type: Boolean,
				default: true
			},
			scoreRole: {},
			action: {
				default: 'CUSTMO',
				type: String
			},
			score: 0,
			controllerStatus: {
				"AUTO_PAGE": false,
				"RIGHT_PAGE": false,
				"SHOW_ANS": false,
				"SHOW_EXPLAN": false,
				"SHOW_RIGHT_OR_ERR": false,
				"SOUND_EXPLAN": false,
				"SOUND_QS": false,
				"SOUND_ON_ERR": false,
				"SOUND_RIGHT_OR_ERR": false,
				"TURN_PAGE": true,
				"AUTO_PAGE": false,
				"RIGHT_PAGE": false
			},
			quesctionlist: [Array],
			currentIndex: [Number],
			useCacheAns: false,
			rightNum: 0,
			errorNum: 0,
			lastIndex: 0,
			ansArr: {},
			ans: null
		},
		watch: {
			rightNum(nv) {
				//console.log('childer r_num', nv)
				this.r_num = nv
			},
			errorNum(nv) {
				//	console.log('childer e_num', nv)
				this.e_num = nv
			},
			'controllerStatus.SOUND_EXPLAN'(nv, ov) {
				//	console.log(nv)
				this.openSoundExplan(nv)
			},
			'controllerStatus.TURN_PAGE'(nv) {
				if (nv) {
					this.$emit('changeStatus', 'TURN_PAGE', nv)
				}
			},
			'controllerStatus.AUTO_PAGE'(nv) {
				if (nv) {
					this.$emit('changeStatus', 'AUTO_PAGE', nv)
				}
			},
			'controllerStatus.RIGHT_PAGE'(nv) {
				if (nv) {
					this.$emit('changeStatus', 'RIGHT_PAGE', nv)
				}
			},
			cur_index(nv, ov) {
				this.$emit('update:currentIndex', nv)
			},
			// r_num(nv) {
			// 	this.$emit('update:rightNum', nv)
			// },
			// e_num(nv) {
			// 	this.$emit('update:errorNum', nv)
			// },
			"cur_qs": {
				handler(n) {
					if (n.img) {
						this.imgUrl = this.$cdn + n.img
					} else {
						this.imgUrl = false
					}
				},
				deep: true
			}
		},

		emits: ['update:lastIndex', 'update:currentIndex', 'update:rightNum', 'update:errorNum', 'changeStatus',
			'removeQueslist', 'submit', 'updatelist'
		],
		data() {
			return {
				lastClick: 0,
				imgUrl: false,
				showImg: false,
				last_qs_ans: [],
				rightList: [],
				real_score: 0,
				r_num: 0,
				e_num: 0,
				errlist: {},
				errinfo: {},
				qs_ans_arr: {},
				qs_ans: [],
				cur_qs: null,
				label: ['A', 'B', 'C', 'D', 'E', 'F'],
				labelAns: {
					'0': 'A',
					'1': 'B',
					'2': 'C',
					'3': 'D',
					'4': 'E',
					'5': 'F'
				},
				AnsOfLable: {
					'A': '0',
					'B': '1',
					'C': '2',
					'D': '3',
					'E': '4',
					'F': '5',
				},
				//判断 为黑色、单选为蓝色、多选为红色。右侧题框里不显示试题序
				textInfo: {
					"0": {
						"value": 0,
						"text": "单选",
						"color": "#0533fc",
						"label": ['A', 'B', 'C', 'D', 'E', 'F'],
						"tips": "操作提示：单选题",
						"getAns": function(cur_qs) {
							if (cur_qs.realProps) {
								return [cur_qs.realProps.realAns]
							} else {
								return '出现异常，联系管理员CODE:7701'
							}
						},
						labelAns: {
							'0': 'A',
							'1': 'B',
							'2': 'C',
							'3': 'D',
							'4': 'E',
							'5': 'F'
						}
					},
					"1": {
						"value": 1,
						"text": "多选",
						"color": "#ff0000",
						"label": ['A', 'B', 'C', 'D', 'E', 'F'],
						"tips": "操作提示：多项选择题",
						"getAns": function(cur_qs) {
							if (cur_qs.realProps) {
								return cur_qs.realProps.realAns.split('|')
							} else {
								return '出现异常，联系管理员CODE:7702'
							}
						},
						labelAns: {
							'0': 'A',
							'1': 'B',
							'2': 'C',
							'3': 'D',
							'4': 'E',
							'5': 'F'
						},
					},
					"2": {
						"value": 2,
						"text": "判断",
						"color": "#000000",
						"label": ['√', '×'],
						"tips": "操作提示：判断题",
						"getAns": function(cur_qs) {
							let label = {
								'A': '√',
								'B': '×'
							}
							return [label[cur_qs.q_ans]]
						},
						labelAns: {
							'0': '√',
							'1': '×',
						},
					},
				},
				cur_index: 0,
				cur_ans_index: 0,
				err_ans_index: [],
				right_ans_index: [],
				user_ans_list: [],
				qs_typeText: [
					'单选',
					'多选',
					'简答'
				],
				soundTaskStatus: null,
				rightFileTempPath: 'right.mp3',
				errFileTempPath: "error.mp3",
				rightIndexList: []
			}
		},
		created() {
			const self = this
			this.qs_ans = this.ans
			this.qs_ans_arr = this.ansArr
			this.cur_index = this.currentIndex
			this.r_num = this.rightNum
			this.e_num = this.errorNum
			if (this.cur_index > 0) {
				this.cur_qs = this.quesctionlist[this.cur_index]
			} else {
				this.cur_qs = this.quesctionlist[0]
			}
			this.errlist = new Set()
			this.errinfo = new Map()
		},
		mounted() {},
		computed: {
			// getShowLast(){
			// 	if(this.cur_index == this.quesctionlist.length-1){
			// 		return false
			// 	}else{
			// 		return true 
			// 	}
			// },
			needResvoe() {
				if (this.cur_qs.lang_txt == 'WY' || this.cur_qs.lang_txt == 'HY') {
					return {
						direction: 'rtl',
						textAlign: 'right',
						unicodeBidi: 'isolate',
						justifyContent: 'flex-end'
					}
				} else {
					return false
				}
			},
			needResvoeFlex() {
				if (this.cur_qs.lang_txt == 'WY' || this.cur_qs.lang_txt == 'HY') {
					return {
						justifyContent: 'flex-end'
					}
				} else {
					return false
				}
			},
			hasLast() {
				let qlen = this.quesctionlist.length - 1
				let status = false
				if (qlen == this.cur_index && !this.cur_qs.showAns) {
					status = true
				}
				//console.log('zui', status)
				return status
			},
			getColor() {
				return {
					color: this.textInfo[this.quesctionlist[this.cur_index].q_type].color
				}
			},
			isRightCp() {
				if (this.cur_qs.q_type != '2') {
					// console.log(this.getChangeAnsFn().join('|') === this.cur_qs.realProps.realAns)
					if (!(this.getChangeAnsFn().join('|') === this.cur_qs.realProps.realAns)) {
						// console.log('错')
						this.errlist.set(this.cur_qs.s_id)
						return false
					}
				} else {
					// console.log(this.labelAns[this.qs_ans.join()], this.cur_qs.q_ans)
					if (!(this.labelAns[this.qs_ans.join()] === this.cur_qs.q_ans)) {
						// console.log('错')
						this.errlist.set(this.cur_qs.s_id)
						return false
					}
				}
				return true
			},
			getChangeAns() {
				let arr = []
				//let labArr [] 
				this.cur_qs.q_struct.forEach((e, i) => {
					if (this.qs_ans.includes(e.index)) {
						arr.push(this.textInfo[this.cur_qs.q_type]['labelAns'][`${i}`])
					}
				})
				return arr
			}
		},
		methods: {
			setLastInfo() {
				this.lastSubmit()
				this.$emit('submit')
			},
			lastSubmit() {
				let ans = false
				if (this.cur_qs.q_type == '1' &&
					this.cur_qs.isright == undefined &&
					this.qs_ans.length > 0) {
					ans = this.showAns(2)
				}

				if (this.cur_qs.q_type != '1' && this.cur_qs.isright == undefined && this.qs_ans.length > 0) {
					ans = this.showAns()
				}

				if (this.cur_qs.isright === false && this.cur_qs.isShowError == undefined) {
					// this.cur_qs.isShowError = true 
					this.$set(this.cur_qs, 'isShowError', true)
					return
				}


			},
			isShowImg() {

				this.showImg = true
				return

				let now = (new Date).getTime()
				if (this.lastClick === 0) {
					this.lastClick = now
					setTimeout(() => {
						this.lastClick = 0
						//	console.log("cacel", this.lastClick)
					}, 400)
					return
				}
				let clickTimes = now - this.lastClick
				if (clickTimes < 400 && clickTimes > 0) {
					this.showImg = true
				}
			},
			saveCache(realScore = 0) {
				const self = this
				let errlist = []
				let errlistremove = []

				const userinfo = uni.getStorageSync('userinfo')
				for (let s of this.errlist.values()) {
					let test_name = this.errinfo.get(s).test_name
					errlist.push({
						q_id: s,
						test_name
					})
					errlistremove.push(s)
				}
				if (errlist.length > 0 && this.action != 'ERROR_LIST') {
					db.collection('error-qlist').where({
						q_id: db.command.in(errlistremove),
						user_id: userinfo._id
					}).remove().then(res => {
						db.collection('error-qlist').add(errlist).then(errAddres => {
						})
					})
				}
				//console.log('uid=>', userinfo._id)


				const formdata = {
					cachedata: {
						r_num: self.r_num,
						e_num: self.e_num,
						qlist: self.quesctionlist,
						ans: self.qs_ans_arr,
						cur_index: self.cur_index,
						cur_ans: self.qs_ans,
						score: realScore
					},
					'cacheType': 'MOCKTEST',
					role: toRaw(self.scoreRole)
				}
				uniCloud.callFunction({
					name: 'saveHistoryv2',
					data: {
						saveData: JSON.stringify(formdata)
					}
				}).then(res => {
					//console.log('save status', res)
				})

				// if(userinfo._id!==undefined &&userinfo._id){
				// 	db.collection('test-history').where({
				// 		user_id: dbCmd.eq(userinfo._id)
				// 	}).remove().then(res => {
				// 		//	console.log(res)
				// 		return 'ok'
				// 	}).then(res => {
				// 		db.collection('test-history')
				// 			.add({
				// 				cachedata: {
				// 					r_num: self.r_num,
				// 					e_num: self.e_num,
				// 					qlist: self.quesctionlist,
				// 					ans: self.qs_ans_arr,
				// 					cur_index: self.cur_index,
				// 					cur_ans: self.qs_ans
				// 				},
				// 				role: self.scoreRole,
				// 				'cacheType': 'MOCKTEST'
				// 			}).then(code => {
				// 				console.log('缓存当前练习' + userinfo._id, code)
				// 			})
				// 	})
				// }
				// if (cacheType == 'DEFAULT') {

				// if(userinfo._id!==undefined && userinfo._id){
				// 	db.collection('test-history').where({
				// 		user_id: dbCmd.eq(userinfo._id)
				// 	}).remove().then(res => {
				// 		//	console.log(res)
				// 		return 'ok'
				// 	}).then(res => {
				// 		db.collection('test-history')
				// 			.add({
				// 				cachedata: {
				// 					r_num: self.r_num,
				// 					e_num: self.e_num,
				// 					qlist: self.quesctionlist,
				// 					ans: self.qs_ans_arr,
				// 					cur_index: self.cur_index,
				// 					cur_ans: self.qs_ans
				// 				},
				// 				role: self.scoreRole,
				// 				'cacheType': 'MOCKTEST'
				// 			}).then(code => {
				// 				console.log('缓存当前练习' + userinfo.uid, code)
				// 			})
				// 	})
				// }	

				// }


				// try {
				// 	const self = this
				// 	let errlist = []
				// 	let errlistremove = []

				// 	// for (let s of this.errlist.values()) {
				// 	// 	errlist.push({
				// 	// 		q_id: s
				// 	// 	})
				// 	// 	errlistremove.push(s)
				// 	// }

				// 	// for (let s of this.quesctionlist) {
				// 	// 	if(s.hasOwnProperty('showAns')==false){
				// 	// 		errlist.push({
				// 	// 			q_id:s.s_id
				// 	// 		})
				// 	// 		errlistremove.push(s.s_id)
				// 	// 	}
				// 	// 	if(s.isright){
				// 	// 		errlistremove.push(s.s_id)
				// 	// 	}
				// 	// }
				// 	const userinfo = uni.getStorageSync('info')
				// 	console.log('uid', userinfo)
				// 	// if (this.rightList.length > 0) {
				// 	// 	db.collection('error-qlist').where({
				// 	// 		q_id: db.command.in(this.rightList),
				// 	// 		user_id: userinfo.uid
				// 	// 	}).remove()
				// 	// }
				// 	console.log('errorlist',errlist)
				// 	// if (errlist.length > 0) {
				// 	// 	db.collection('error-qlist').where({
				// 	// 		q_id: db.command.in(errlistremove),
				// 	// 		user_id: userinfo.uid
				// 	// 	}).remove().then(res => {
				// 	// 		db.collection('error-qlist').add(errlist).then(resError => {
				// 	// 			console.log('error list ',resError)
				// 	// 		})
				// 	// 	})
				// 	// }
				// 	const cachedata = {
				// 		'cachedata': {
				// 			r_num: self.r_num,
				// 			e_num: self.e_num,
				// 			qlist: self.quesctionlist,
				// 			ans: self.qs_ans_arr,
				// 			cur_index: self.cur_index,
				// 			cur_ans: self.qs_ans
				// 		},
				// 		'role': self.scoreRole,
				// 		'time': self.getTestTime,
				// 		'cacheType': 'MOCKTEST'
				// 	}
				// 	console.log(cachedata)

				// 	// if (cacheCurrentHistory == true) {
				// 	// 	console.log('test mock need cache')
				// 	// 	db.collection('test-history').where({
				// 	// 		user_id: dbCmd.eq(userinfo.uid)
				// 	// 	}).remove().then(res => {
				// 	// 		//	console.log(res)
				// 	// 		return 'ok'
				// 	// 	}).then(resP => {
				// 	// 		db.collection('test-history')
				// 	// 			.add(cachedata).then(code => {
				// 	// 				console.log(code)
				// 	// 			})
				// 	// 	})
				// 	// }

				// 	console.log('test mock end')
				// } catch (e) {
				// 	console.log(e)
				// }


			},
			getEndTime() {

			},
			resetError() {
				this.cur_index = 0
				this.qs_ans = []
				this.r_num = 0
				this.e_num = 0
				this.removeQueslist()
				this.$emit('update:rightNum', this.r_num)
				this.$emit('update:errorNum', this.e_num)
				this.qs_ans_arr = {}
				this.cur_qs = this.quesctionlist[0]
				for (let s of this.quesctionlist) {
					delete s.showAns
					delete s.isright
					delete s.ansLabel
					if (s.check) {
						s.check = [false, false, false, false, false, false]
					}
				}
			},
			resetAll() {
				this.cur_index = 0
				this.cur_qs = this.quesctionlist[0]
				this.qs_ans = []
				this.r_num = 0
				this.e_num = 0
				this.qs_ans_arr = {}
				for (let s of this.quesctionlist) {
					delete s.showAns
					delete s.isright
					delete s.ansLabel
					if (s.check) {
						s.check = [false, false, false, false, false, false]
					}
				}
			},
			createdAudio(url) {
				this.soundTaskStatus = uni.createInnerAudioContext();
				this.soundTaskStatus.autoplay = true;
				this.soundTaskStatus.src = this.$cdn + url
				this.soundTaskStatus.onPlay(() => {
					//	console.log('开始播放');
				});
				this.soundTaskStatus.onError((res) => {
					// uni.showModal({
					// 	title: '资源无法访问!',
					// 	content: '资源无法访问!'
					// })
				});
			},
			getCurChangeAns() {
				return this.qs_ans
			},
			getLastChangeAns() {
				return this.last_qs_ans
			},
			openSoundQs() {
				if (this.soundTaskStatus) {
					this.soundTaskStatus.destroy()
				}
				if (!this.cur_qs.auto_sound) {
					uni.showToast({
						title: '此题暂无音频讲解',
						duration: 2000,
						icon: 'none'
					})
					return
				}
				this.createdAudio('sound/' + this.cur_qs.auto_sound)
			},
			openSoundExplan(status) {
				if (this.soundTaskStatus) {
					this.soundTaskStatus.destroy()
				}
				if (status) {
					if (!this.cur_qs.sound) {
						uni.showToast({
							title: '此题暂无音频讲解',
							duration: 2000,
							icon: 'none'
						})
						return
					}
					this.createdAudio(this.cur_qs.sound)
				}
			},
			getChangeAnsFn() {
				let arr = []
				this.cur_qs.q_struct.forEach((e, i) => {
					if (this.qs_ans.includes(e.index)) {
						arr.push(this.textInfo[this.cur_qs.q_type]['labelAns'][`${i}`])
					}
				})
				arr.sort()
				return arr
			},
			async isRightFn() {
				let ans = ''
				let ans_status = true
				if (this.cur_qs.q_type != '2') {
					ans = this.getChangeAnsFn().join('|')
					if (!(ans === this.cur_qs.realProps.realAns)) {
						ans_status = false
						this.errlist.add(this.cur_qs.s_id)
						this.errinfo.set(this.cur_qs.s_id, {
							test_name: this.cur_qs.testpaper_name
						})
					}
				} else {
					ans = this.labelAns[this.qs_ans.join()]
					if (!(ans === this.cur_qs.q_ans)) {
						ans_status = false
						this.errlist.add(this.cur_qs.s_id)
						this.errinfo.set(this.cur_qs.s_id, {
							test_name: this.cur_qs.testpaper_name
						})
					}
				}

				this.$set(this.cur_qs, 'isright', ans_status)
				this.$set(this.cur_qs, 'showAns', true)
				this.$emit('updatelist', {
					index: this.cur_index,
					obj: this.cur_qs
				})

				await this.$nextTick()
				if (ans_status) {
					this.r_num++
					// let a = this.r_num + 1
					this.rightIndexList.push(this.cur_index)
					this.rightList.push(this.cur_qs.s_id)
					this.$emit('update:rightNum', this.r_num)
				} else {
					this.e_num++
					this.$emit('update:errorNum', this.e_num)
				}

				if (this.cur_qs.q_type == '2') {
					this.cur_qs.ansLabel = ans == 'A' ? '√' : "✘"
				} else {
					this.cur_qs.ansLabel = this.getChangeAnsFn().join('')
				}

				// this.cur_qs.isright = ans_status
				if (this.controllerStatus.AUTO_PAGE) {
					this.next()
					return
				}
				if (this.controllerStatus.RIGHT_PAGE && ans_status == true) {
					this.next()
					return
				}
				if (this.controllerStatus.SOUND_RIGHT_OR_ERR) {
					let url = ans_status ? this.rightFileTempPath : this.errFileTempPath
					this.createdAudio(url)
				}
				if (this.controllerStatus.SOUND_ON_ERR && ans_status == false) {
					setTimeout(() => this.createdAudio(this.cur_qs.sound), 1000)
				}
				return ans_status
			},
			isError() {},
			onCheckChange(e) {
				let ans_temp = []
				for (let s of e.detail.value) {
					let target = this.cur_qs.q_struct[s].index
					ans_temp.push(target)
				}
				this.qs_ans = ans_temp
				this.qs_ans_arr[this.cur_qs.s_id] = this.qs_ans
				if (this.cur_qs.q_type == '1') {
					for (let s of e.detail.value) {
						this.cur_qs.check[s] = true
					}
				}
			},
			// onCheckChange(e) {
			// 	//console.log(e.target.checked, e.target.value)
			// 	let target = this.cur_qs.q_struct[e.target.value].index
			// 	if (e.target.checked && this.cur_qs.isright != undefined) {
			// 		this.qs_ans.push(target)
			// 	} else {
			// 		let position = this.qs_ans.indexOf(target)
			// 		if (position) {
			// 			this.qs_ans.splice(position, 1)
			// 		}
			// 	}

			// },

			next() {
				const self = this

				// if(this.cur_qs.q_type=='1'){
				// 	if(Object.keys(this.qs_ans).length==0){
				// 		uni.showModal({
				// 			content:'你还没有选择答案'
				// 		})
				// 		return
				// 	} 
				// }
				if (this.cur_index == this.quesctionlist.length - 1) {
					return false
				}

				if (this.cur_index < this.quesctionlist.length - 1) {
					this.skipQs(this.cur_index + 1, 'next')
				} else {
					uni.showModal({
						content: '是否提交?',
						title: 'tips',
						success(res) {
							if (res.confirm) {

								//	self.totalNumber()
								//	self.submitStatus = true
								//	self.allStatus = true
							}
						}
					})
				}
			},
			last() {
				if (this.cur_index != 0) {
					//this.set_loc_history(this.cur_qs_id)
					// if(this.cur_qs.q_type=='1'){
					// 	if(Object.keys(this.qs_ans).length==0){
					// 		uni.showModal({
					// 			content:'你还没有选择答案'
					// 		})
					// 		return
					// 	} 
					// }
					this.skipQs(this.cur_index - 1, 'last')
				}
			},
			async skipQs(index, action) {

				if (this.cur_index === index) {
					return
				}

				let ans = false

				if (this.cur_qs.q_type == '1' &&
					this.cur_qs.isright == undefined &&
					action != 'cust_skip' &&
					this.qs_ans.length > 0) {
					ans = await this.showAns(2)
				}
				if (this.cur_qs.q_type != '1' && this.cur_qs.isright == undefined && this.qs_ans.length > 0) {
					ans = await this.showAns()
				}

				if (this.cur_qs.isright != undefined) {
					ans = this.cur_qs_isright
				}
				//做错的时候显示错题，并且增加只显示一次的标识



				if (this.cur_qs.isright === false && this.cur_qs.isShowError == undefined) {
					// this.cur_qs.isShowError = true 
					this.$set(this.cur_qs, 'isShowError', true)
					return
				}

				this.cur_index = index
				this.resetStatus()
				this.cur_qs = this.quesctionlist[this.cur_index]
				this.getCurrQsStatus()
			},
			resetStatus() {
				this.qs_ans_arr[this.cur_qs.s_id] = this.qs_ans
				this.qs_ans = []
				if (this.soundTaskStatus) {
					this.soundTaskStatus.destroy()
					this.soundTaskStatus = null
				}
			},
			getCurrQsStatus() {
				if (this.qs_ans_arr[this.cur_qs.s_id]) {
					this.qs_ans = this.qs_ans_arr[this.cur_qs.s_id]
				}
			},
			tiggerItem(id, checkIndex) {
				if (this.cur_qs.showAns) {
					return
				}
				const position = this.qs_ans.indexOf(id)
				if (this.qs_ans.length >= 1 && this.cur_qs.q_type != '1') {
					this.qs_ans = []
				}
				if (position === -1) {
					this.qs_ans.push(id)
					this.qs_ans_arr[this.cur_qs.s_id] = this.qs_ans

				} else {
					this.qs_ans.splice(position, 1)
					this.qs_ans_arr[this.cur_qs.s_id] = this.qs_ans
				}
				if (this.cur_qs.q_type == '1') {
					this.cur_qs.check[checkIndex] = !this.cur_qs.check[checkIndex]
				} else {

					if (this.cur_qs.check[checkIndex] == true) {
						this.$set(this.cur_qs.check, checkIndex, false)
						return
					}

					for (let position of [0, 1, 2, 3]) {
						this.$set(this.cur_qs.check, position, false)
					}
					this.$set(this.cur_qs.check, checkIndex, true)
				}
			},
			async showAns(type) {
				let ans = true
				if (this.cur_qs.q_type != 1) {
					ans = await this.isRightFn()
				}
				if (type) {
					ans = await this.isRightFn()
				}
				return ans
			},
			removeQueslist() {
				this.$emit('removeQueslist', this.rightList)
				this.rightIndexList = []
				this.rightList = []
			}
		},
	}
</script>

<style scoped lang="scss">
	@import url('./testcontroller.css');
</style>
